package cn.aylog.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JdbcDemo {
    public static void main(String[] args) throws Exception {
        // 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        // 获取连接
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC","root", "123456");
        // sql
        String sql = "select * from `user`";
        // 预处理
        PreparedStatement stmt = conn.prepareStatement(sql);
        // 执行
        ResultSet rs = stmt.executeQuery();
        // 处理结果
        System.out.println(rs);

        // 关闭资源
        rs.close();
        stmt.close();
        conn.close();

    }
}
